package com.company;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @date : 2022/7/22 15:51
 * Java虚拟机安全点验证
 * https://mp.weixin.qq.com/s/KDUccdLALWdjNBrFjVR74Q
 */

public class P021_HotSpotSafePoint {

    public static AtomicInteger num = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            for (int i = 0; i < 200000000; i++) {
                num.getAndAdd(1);
            }
        };
        Thread t1 = new Thread(runnable, "测试01线程");
        Thread t2 = new Thread(runnable, "测试02线程");
        t1.start();
        t2.start();
        System.out.println(Thread.currentThread().getName() + " 主线程开始睡觉");
        //记录睡眠时间
        long start = System.currentTimeMillis();
        Thread.sleep(1000);

        System.out.println(Thread.currentThread().getName() + " 睡醒了, 一共睡了 : " + (System.currentTimeMillis() - start) + " 毫秒");
        System.out.println(Thread.currentThread().getName() + " 打印一下num 看看结果是多少: " + num);
    }
}
